import time
import pytest
import allure
import TestCase

from Base.InitDriver import init_driver
from Page.CommonPage import CommonPage
from Utils.XiaoMaUtils import XiaoMaUtils


@allure.feature('TestCase_05: 去完成按钮页面跳转任务页面	')
@allure.issue(
    'https://www.tapd.cn/54441127/sparrow/tcase/view/1154441127001044366?url_cache_key=5b07a59231afaf505fb7dc2f4205dfae')
class TestCasePersonal05:
    def setup_class(self):
        self.driver = init_driver()
        # 实例化页面
        # 桌面
        self.launcher_index_page = CommonPage(self.driver).get_launcher_index_page()
        self.launcher_app_list_page = CommonPage(self.driver).get_launcher_app_list_page()
        # 个人中心
        self.personal_index_page = CommonPage(self.driver).get_personal_index_page()
        self.personal_account_select_page = CommonPage(self.driver).get_personal_account_select_page()
        self.personal_authorize_open_page = CommonPage(self.driver).get_personal_authorize_open()
        self.personal_authorize_open_two_page = CommonPage(self.driver).get_personal_authorize_open_two()
        self.personal_authorize_page = CommonPage(self.driver).get_personal_authorize()
        self.personal_avatar_page = CommonPage(self.driver).get_personal_avatar()
        self.personal_binding_page = CommonPage(self.driver).get_personal_binding_page()
        self.personal_car_info_page = CommonPage(self.driver).get_personal_carinfo_page()
        self.personal_car_number_page = CommonPage(self.driver).get_personal_carnumber_page()
        self.personal_certification_page = CommonPage(self.driver).get_personal_certification()
        self.personal_edit_information_page = CommonPage(self.driver).get_personal_edit_information()
        self.personal_face_recognition_page = CommonPage(self.driver).get_personal_face_recognition()
        self.personal_feedback_page = CommonPage(self.driver).get_personal_feedback_page()
        self.personal_feed_result_page = CommonPage(self.driver).get_personal_feed_result_page()
        self.personal_forget_password_page = CommonPage(self.driver).get_personal_forget_password()
        self.personal_key_page = CommonPage(self.driver).get_personal_key_page()
        self.personal_letter_page = CommonPage(self.driver).get_personal_letter()
        self.personal_logout_page = CommonPage(self.driver).get_personal_logout_page()
        self.personal_my_coin_page = CommonPage(self.driver).get_personal_my_coin_page()
        self.personal_my_new_page = CommonPage(self.driver).get_personal_feed_my_new_page()
        self.personal_my_order_page = CommonPage(self.driver).get_personal_my_order_page()
        self.personal_name_toast_page = CommonPage(self.driver).get_personal_name_toast()
        self.personal_new_content_page = CommonPage(self.driver).get_personal_feed_my_new_content_page()
        self.personal_password_page = CommonPage(self.driver).get_personal_password_page()
        self.personal_qr_code_page = CommonPage(self.driver).get_personal_qrcode_page()
        self.personal_setting_page = CommonPage(self.driver).get_personal_setting_page()
        self.personal_sex_toast_page = CommonPage(self.driver).get_personal_sex_toast()
        self.personal_task_page = CommonPage(self.driver).get_personal_task_page()
        self.personal_new_guide_page = CommonPage(self.driver).get_personal_new_guide_page()
        self.personal_listen_songs_page = CommonPage(self.driver).get_personal_listen_songs()

    def teardown_class(self):
        XiaoMaUtils.close_app('personal')
        XiaoMaUtils.close_app('launcher')
        # XiaoMaUtils.clear_data('personal')
        self.driver.quit()

    @allure.story('step1:点击应用页')
    @pytest.mark.run(order=51)
    def test_personal_05_1_click_list(self):
        try:
            self.launcher_index_page.click_app_list()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step2: 点击列表中的个人中心图标,查看是否启动")
    @pytest.mark.run(order=52)
    def test_personal_05_2_click_personal(self):
        try:
            self.launcher_app_list_page.click_appname(TestCase.PERSONAL)
            self.personal_index_page.is_display_personal_index()
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)

    @allure.story("step3: 点击去完成按钮")
    @pytest.mark.run(order=53)
    def test_personal_05_3_click_personal(self):
        try:
            self.personal_index_page.click_list_category("任务中心")
            self.personal_task_page.is_display_personal_task()
            text = self.personal_task_page.get_ele_text(self.personal_task_page.get_list_daily_task_description())
            a = "使用听歌识曲功能识别音乐并收听1次，获得1车币"
            if text == a:
                self.personal_task_page.click_list_daily_task_done()
                b = self.personal_listen_songs_page.is_display_personal_song()
                if b == True:
                    print("进入听歌识曲成功,目前无法完整听完一首歌")
                else:
                    print("打开听歌识曲错误")
            else:
                self.personal_task_page.click_list_daily_task_done(index=2)
                self.personal_task_page.click_list_daily_task_done()
                b = self.personal_listen_songs_page.is_display_personal_song()
                if b == True:
                    print("进入听歌识曲成功,目前无法完整听完一首歌")
                else:
                    print("打开听歌识曲错误")
        except Exception as e:
            raise e
        finally:
            allure.attach(self.driver.get_screenshot_as_png(), XiaoMaUtils.get_current_time(),
                          allure.attachment_type.PNG)


if __name__ == 'main__':
    # pass
    pytest.main("-s testcase_personal_05.py")
